home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / mathpack / saxpy.f < prev    next >
Text File  |  1989-08-17  |  4KB  |  99 lines

  1. c   imsl routine name   - vbla=saxpy                                    vbsb0010
  2. c
  3. c-----------------------------------------------------------------------
  4. c
  5. c   computer            - vax/single
  6. c
  7. c   latest revision     - january 1, 1978
  8. c
  9. c   purpose             - compute a constant times a vector plus
  10. c                           a vector, all single precision
  11. c
  12. c   usage               - call saxpy (n,sa,sx,incx,sy,incy)
  13. c
  14. c   arguments    n      - length of vectors x and y. (input)
  15. c                sa     - real scalar. (input)
  16. c                sx     - real vector of length max(n*iabs(incx),1).
  17. c                           (input)
  18. c                incx   - displacement between elements of sx. (input)
  19. c                           x(i) is defined to be..
  20. c                           sx(1+(i-1)*incx) if incx.ge.0 or
  21. c                           sx(1+(i-n)*incx) if incx.lt.0.
  22. c                sy     - real vector of length max(n*iabs(incy),1).
  23. c                           (input/output)
  24. c                           saxpy replaces y(i) with sa*x(i)+y(i)
  25. c                           for i=1,...,n.
  26. c                           x(i) and y(i) refer to specific elements
  27. c                           of sx and sy, respectively. see incx and
  28. c                           incy argument descriptions.
  29. c                incy   - displacement between elements of sy. (input)
  30. c                           y(i) is defined to be..
  31. c                           sy(1+(i-1)*incy) if incy.ge.0 or
  32. c                           sy(1+(i-n)*incy) if incy.lt.0.
  33. c
  34. c   precision/hardware  - single/all
  35. c
  36. c   reqd. imsl routines - none required
  37. c
  38. c   notation            - information on special notation and
  39. c                           conventions is available in the manual
  40. c                           introduction or through imsl routine uhelp
  41. c
  42. c   copyright           - 1978 by imsl, inc. all rights reserved.
  43. c
  44. c   warranty            - imsl warrants only that imsl testing has been
  45. c                           applied to this code. no other warranty,
  46. c                           expressed or implied, is applicable.
  47. c
  48. c-----------------------------------------------------------------------
  49. c
  50.       subroutine saxpy  (n,sa,sx,incx,sy,incy)
  51. c
  52. c                                  specifications for arguments
  53.       integer            n,incx,incy
  54.       real               sx(1),sy(1),sa
  55. c                                  specifications for local variables
  56.       integer            i,ix,iy,m,mp1,ns
  57. c                                  first executable statement
  58.       if (n.le.0.or.sa.eq.0.e0) return
  59.       if (incx.eq.incy) if (incx-1) 5,15,35
  60.     5 continue
  61. c                                  code for nonequal or nonpositive
  62. c                                    increments.
  63.       ix = 1
  64.       iy = 1
  65.       if (incx.lt.0) ix = (-n+1)*incx+1
  66.       if (incy.lt.0) iy = (-n+1)*incy+1
  67.       do 10 i=1,n
  68.          sy(iy) = sy(iy)+sa*sx(ix)
  69.          ix = ix+incx
  70.          iy = iy+incy
  71.    10 continue
  72.       return
  73. c                                  code for both increments equal to 1
  74. c                                    clean-up loop so remaining vector
  75. c                                    length is a multiple of 4.
  76.    15 m = n-(n/4)*4
  77.       if (m.eq.0) go to 25
  78.       do 20 i=1,m
  79.          sy(i) = sy(i)+sa*sx(i)
  80.    20 continue
  81.       if (n.lt.4) return
  82.    25 mp1 = m+1
  83.       do 30 i=mp1,n,4
  84.          sy(i) = sy(i)+sa*sx(i)
  85.          sy(i+1) = sy(i+1)+sa*sx(i+1)
  86.          sy(i+2) = sy(i+2)+sa*sx(i+2)
  87.          sy(i+3) = sy(i+3)+sa*sx(i+3)
  88.    30 continue
  89.       return
  90. c                                  code for equal, positive, nonunit
  91. c                                    increments.
  92.    35 continue
  93.       ns = n*incx
  94.       do 40 i=1,ns,incx
  95.          sy(i) = sa*sx(i)+sy(i)
  96.    40 continue
  97.       return
  98.       end
  99.